package com.wsc.springbootmultidevdemo.msg.topic;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.wsc.springbootmultidevdemo.msg.ConnectionUtil;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * mq topic 模式,交换机模糊匹配路由键
 */
public class Send {
    public static void main(String[] args) throws IOException, TimeoutException {
        Connection connection = ConnectionUtil.getConnection();
        Channel channel = connection.createChannel();

        String EXCHANGE_NAME = "exchange.topic.x";
        String[] routingKeys = {"quick.orange.rabbit", "lazy.orange.elephant", "mq.erlang.rabbit", "lazy.brown.fox","lazy."};
        for (int i = 0; i <routingKeys.length; i++) {
            String message = "hello rabbit - "+routingKeys[i];
            channel.basicPublish(EXCHANGE_NAME,routingKeys[i],null,message.getBytes());
        }

        channel.close();
        connection.close();
    }
}
